package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.WmsWarehouseBase;
import com.ruoyi.system.domain.vo.SelectVo;
import com.ruoyi.system.domain.vo.TreeVo;
import com.ruoyi.system.mapper.WmsWarehouseBaseMapper;
import com.ruoyi.system.service.IWmsWarehouseBaseService;
import com.ruoyi.system.utils.TreeGeneratorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 仓库基础信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-12
 */
@Service
public class WmsWarehouseBaseServiceImpl implements IWmsWarehouseBaseService
{
    @Autowired
    private WmsWarehouseBaseMapper wmsWarehouseBaseMapper;

    /**
     * 查询仓库基础信息
     *
     * @param warehouseId 仓库基础信息主键
     * @return 仓库基础信息
     */
    @Override
    public WmsWarehouseBase selectWmsWarehouseBaseByWarehouseId(Long warehouseId)
    {
        return wmsWarehouseBaseMapper.selectWmsWarehouseBaseByWarehouseId(warehouseId);
    }

    /**
     * 查询仓库基础信息列表
     *
     * @param wmsWarehouseBase 仓库基础信息
     * @return 仓库基础信息
     */
    @Override
    public TableDataInfo<WmsWarehouseBase> selectWmsWarehouseBaseList(WmsWarehouseBase wmsWarehouseBase, PageQuery pageQuery)
    {
        Page<WmsWarehouseBase> page = wmsWarehouseBaseMapper.selectWmsWarehouseBaseList(pageQuery.build(),wmsWarehouseBase);
        return TableDataInfo.build(page);
    }

    /**
     * 新增仓库基础信息
     *
     * @param wmsWarehouseBase 仓库基础信息
     * @return 结果
     */
    @Override
    public int insertWmsWarehouseBase(WmsWarehouseBase wmsWarehouseBase)
    {
        wmsWarehouseBase.setCreateTime(DateUtils.getNowDate());
        return wmsWarehouseBaseMapper.insertWmsWarehouseBase(wmsWarehouseBase);
    }

    /**
     * 修改仓库基础信息
     *
     * @param wmsWarehouseBase 仓库基础信息
     * @return 结果
     */
    @Override
    public int updateWmsWarehouseBase(WmsWarehouseBase wmsWarehouseBase)
    {
        wmsWarehouseBase.setUpdateTime(DateUtils.getNowDate());
        return wmsWarehouseBaseMapper.updateWmsWarehouseBase(wmsWarehouseBase);
    }

    /**
     * 批量删除仓库基础信息
     *
     * @param warehouseIds 需要删除的仓库基础信息主键
     * @return 结果
     */
    @Override
    public int deleteWmsWarehouseBaseByWarehouseIds(Long[] warehouseIds)
    {
        return wmsWarehouseBaseMapper.deleteWmsWarehouseBaseByWarehouseIds(warehouseIds);
    }

    /**
     * 删除仓库基础信息信息
     *
     * @param warehouseId 仓库基础信息主键
     * @return 结果
     */
    @Override
    public int deleteWmsWarehouseBaseByWarehouseId(Long warehouseId)
    {
        return wmsWarehouseBaseMapper.deleteWmsWarehouseBaseByWarehouseId(warehouseId);
    }


    @Override
    public List<SelectVo> getWarehouseSelect()
    {
        return wmsWarehouseBaseMapper.getWarehouseSelect();
    }

    @Override
    public List<TreeVo>  queryWarehouseTree(){
        List<TreeVo> treeVos = wmsWarehouseBaseMapper.queryWarehouseTree();
        // 构建树形结构
        List<TreeVo> warehouseTree = TreeGeneratorUtil.buildCategoryTree(treeVos);
        return warehouseTree;
    }
}
